package com.llkj.qingnianguoxue.mine;

import android.os.Bundle;
import android.widget.EditText;

import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.base.BaseActivity;
import com.llkj.qingnianguoxue.base.ConstantUserInfo;
import com.llkj.qingnianguoxue.base.MyApplication;
import com.llkj.qingnianguoxue.bean.ResponseBean;
import com.llkj.qingnianguoxue.http.HttpMethod;
import com.llkj.qingnianguoxue.util.GsonUtil;
import com.llkj.qingnianguoxue.util.StringUtils;
import com.llkj.qingnianguoxue.util.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 修改个性签名
 */
public class ModifySignatureActivity extends BaseActivity {

    @BindView(R.id.et_signature)
    EditText etSignature;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_modify_signature);
        setTitle("个性签名", true, TITLE_TYPE_IMG, R.drawable.icon_back, true,TITLE_TYPE_TEXT,"保存");
        initStatusbar(TSATUSBAR_TYPE_BLACK_TEXT,rlTitle,R.color.gray_bar);
        ButterKnife.bind(this);

        String signatureP = MyApplication.getInstance().sputil.getString(ConstantUserInfo.USER_SIGNATURE);
        etSignature.setText(signatureP);
    }

    @Override
    protected void rightDoWhat() {
        super.rightDoWhat();
        String signature = etSignature.getText().toString();
        String signatureP = MyApplication.getInstance().sputil.getString(ConstantUserInfo.USER_SIGNATURE);
        if(StringUtils.isEmpty(signature) || signature.equals(signatureP)){
            ToastUtil.makeLongText(this,getString(R.string.signature_input));
            return;
        }
        loadWaitDialog();
        HttpMethod.userEdit(this, this, signature,null, null, null, null, null, null);

    }

    @Override
    protected void onhttpSuccess(String data, int method) {
        super.onhttpSuccess(data, method);
        if (method == HttpMethod.HTTP_USER_EDIT) {
            ToastUtil.makeLongText(this, "修改成功");
            ResponseBean responseBean = GsonUtil.GsonToBean(data, ResponseBean.class);
            if (responseBean != null) {
                String signature = etSignature.getText().toString();
                MyApplication.getInstance().sputil.put(ConstantUserInfo.USER_SIGNATURE,signature);
                setResult(RESULT_OK);
                finish();
            }
        }
    }
}
